// JavaScript Document

var IMG = 'http://localhost/BestBuddies/style/images/';
var CONTROLLERS = 'http://localhost/BestBuddies/';

function login(){
	returnVar = true;
	
	email = $("#email").val();
	password = $("#password").val();	
	
	$.ajax({
      url: CONTROLLERS+'user/check_user/string',
      global: false,
      type: "POST",
      data: ({email : email,
	  		  password : password}),
      async:false,
	  dataType:"html",
      success: function(msg){
		if(msg.indexOf("error1") != -1){
			alert('Combinaci\u00f3n err\u00f3nea de Correo y Contrase\u00f1a');
			returnVar = false;
		}
		else if(msg == 'error2'){
			alert('Integrante pendiente, en espera por aprobaci\u00f3n');
			returnVar = false;
		}
      }
	})
	
	return returnVar;
}

function get_employee_detail(id){
	$("#employee_detail_div"+id).toggle();
	$("#employee_detail_div"+id).html('<img src="'+IMG+'loading.gif">');
	
	$.ajax({
      url: CONTROLLERS+'management/employee_detail/'+id,
      global: false,
      type: "POST",
      data: ({}),
      async:false,
	  dataType:"html",
      success: function(msg){
		$("#employee_detail_div"+id).html(msg);
      }
	})
}

function get_user_detail(id){
	$("#user_detail_div"+id).toggle();
	$("#user_detail_div"+id).html('<img src="'+IMG+'loading.gif">');
	
	$.ajax({
      url: CONTROLLERS+'management/user_detail/'+id,
      global: false,
      type: "POST",
      data: ({}),
      async:false,
	  dataType:"html",
      success: function(msg){
		$("#user_detail_div"+id).html(msg);
      }
	})
}

function set_search_field(){
	var type = $("#type").val();
	if(type == 'status'){
		var field = '<select name="text" id="text"> <option value="activo">Activo</option> <option value="inactivo">Inactivo</option> <option value="pendiente">Pendiente</option> </select>';
		$("#text_field_div").html(field);
	}
	else{
		var field = '<input type="text" name="text" id="text">';
		$("#text_field_div").html(field);
	}
}

function check_period_code(id_period){	
	returnVar = true;
	periodCode = $("#periodCode").val();
	
	$.ajax({
      url: CONTROLLERS+'management/check_period_code',
      global: false,
      type: "POST",
      data: ({periodCode : periodCode,
	  		  id_period : id_period}),
      async:false,
	  dataType:"html",
      success: function(msg){
		if(msg.indexOf("error") != -1){
			alert('El codigo ya existe para un periodo almacenado');
			returnVar = false;
		}
      }
	})
	
	return returnVar;
}











